%Clean a given set of equations from every repeated equation.
%
%Clean a given set of equations from every repeated equation. The function
%checks one by one the given equations and create a new array with the same
%information as the input but without repeated equations.
%
%Prototype: [clearedEquations] = clearEquation( equations )
%
%Input:     equations - An array that has a single equation for every
%           cell. The equations are all equal to 0, and you only need to
%           specify the left member of every single equation without "= 0".
%
%Output:    clearedEquations - An array that cointains the same information
%           of the input, but without useless repeated equations.

function [ clearedEquations ] = clearEquation( equations )

%k is the current position in the output array. This index is used in order
%to add further equations in the correct position in the output array.
k = 1;

for i = 1:length(equations)
    repeated = false;
    
    %Check if the i-th equation is repeated in the next equations. Doing
    %so, the last occorrence of an equation is the right one for the output
    %array.
    for j = (i+1):length(equations)
        if strcmp(char(equations(i)),char(equations(j)))
            repeated = true;
        end
    end
    
    %If the i-th equation has no repetitions, it is added to the output
    %array at the k-th cell, and then k is increased by 1.
    if ~repeated
        clearedEquations(k) = equations(i);
        k = k + 1;
    end
    
end

return;

end
